//
//  HXInsideAllProfessionViewController.m
//  GiftSay
//
//  Created by laohu on 16/1/11.
//  Copyright © 2016年 liyinkai. All rights reserved.
//

#import "HXInsideAllProfessionViewController.h"
#import "HXInsideLongCell.h"
#import "HomeNewModel.h"
@interface HXInsideAllProfessionViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation HXInsideAllProfessionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSString *url = [NSString stringWithFormat:kInsideAllProfession, self.model.ids];
    
    
    
//    NSLog(@"%@", url);
    [self getData:url];
    
    
    self.navigationItem.title = self.model.title;
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backToCatagory:)];
    self.navigationItem.leftBarButtonItem = button;
    
    self.navigationItem.rightBarButtonItem = nil;

}

- (void)setModel:(HXTactikFirstModel *)model {
    _model = model;
    NSString *url = [NSString stringWithFormat:kInsideAllProfession, model.ids];
    
    [self getData:url];
    
}

- (void)backToCatagory:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:NO];
}
- (void)createView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 49) style:UITableViewStyleGrouped];
//    self.tableView.backgroundColor = [UIColor redColor];
    [self.tableView registerClass:[HXInsideLongCell class] forCellReuseIdentifier:@"InsideAllCatagory"];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:_tableView];
}


- (void)getData:(NSString *)url {
    [LYKNetWorkTool getWithUrl:url parameter:nil httpHeader:nil resposeType:ResponseTypeJSON success:^(id(success)) {
//        NSLog(@"%@", success);
        NSDictionary *dic = success[@"data"];
        NSArray *arr = dic[@"posts"];
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dictionary in arr) {
            HomeNewModel *model = [[HomeNewModel alloc] initWithDictionary:dictionary];
//            NSLog(@"%@", model);
            [array addObject:model];
        }
        self.dataSource = [NSMutableArray arrayWithArray:array];
        [self createView];
    } fail:^(NSError *error) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HXInsideLongCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InsideAllCatagory"];
    cell.model = self.dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return (self.view.height - 40) / 3;
}




#pragma mark - longCell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSLog(@"不不不不不不不不不");
    //webviewurl
    [self.dataSource[indexPath.row] content_url];
    [self.dataSource[indexPath.row] url];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
